package cn.kmsoft.spatialboot.controller;

import cn.kmsoft.stgeometry.constant.DBConfig;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

public class BaseController {

    @Autowired
    private Environment env;

    @Value("${spring.profiles.active}")
    protected String profilesActive;
    @Value("${analyst.testshppath}")
    protected String testshpPath;

    public Map<String, DBConfig> loadDBConfig(){
        String[] jdbcDrivers = env.getProperty("db.driver").split(";");
        String[] driverClassNames = env.getProperty("db.jdbc.driverClassName").split(";");
        String[] dbInstances = env.getProperty("db.jdbc.name").split(";");//数据库实例名称
        String[] dbTypeNames= env.getProperty("db.type.name").split(";");
        String[] urls = env.getProperty("db.jdbc.url").split(";");

        Map<String, DBConfig> dbConfigsHashMap = new HashMap<String, DBConfig>();
        for (int i = 0; i < dbInstances.length; i++) {
            DBConfig dbConfig = new DBConfig();

            String dbInstance = dbInstances[i].trim();
            dbConfig.setDbInstance(dbInstance);
            dbConfig.setDbTypeName(dbTypeNames[i].trim());
            dbConfig.setJdbcDriver(jdbcDrivers[i].trim());
            dbConfig.setDriverClassName(driverClassNames[i].trim());
            dbConfig.setDbUrl(urls[i].trim());

            dbConfigsHashMap.put(dbInstance,dbConfig);
        }

        return dbConfigsHashMap;
    }

}
